package prickworlds.game.templates;

import org.w3c.dom.Element;

public class WeaponTemplate extends Template {
	/**
	 * radius of the bullet
	 */
	float bulletRadius;
	int reloadTime;
	int damage;
	float speed;
	float acceleration;
	String name;

	public WeaponTemplate(String weaponName, float radius, int reloadTime,
			int damage, float speed, float acceleration) {
		this.name = weaponName;
		this.bulletRadius = radius;
		this.name = weaponName;
		this.reloadTime = reloadTime;
		this.damage = damage;
		this.speed = speed;
		this.acceleration = acceleration;
	}

	private WeaponTemplate() {
		// TODO Auto-generated constructor stub
	}

	public float getRadius() {
		return bulletRadius;
	}

	public int getReloadTime() {
		return reloadTime;
	}

	public String getWeaponName() {
		return name;
	}

	public int getDamage() {
		return damage;
	}

	public float getSpeed() {
		return speed;
	}

	public float getAcceleration() {
		return acceleration;
	}

	public void setRadius(float radius) {
		this.bulletRadius = radius;
	}

	public void setDamage(int damage) {
		this.damage = damage;
	}

	public void setReloadTime(int reloadTime) {
		this.reloadTime = reloadTime;
	}

	public void setSpeed(float speed) {
		this.speed = speed;
	}

	public void setAcceleration(float acceleration) {
		this.acceleration = acceleration;
	}

	public void setWeaponName(String weaponName) {
		this.name = weaponName;
	}

	public static WeaponTemplate loadWeaponTemplate(String filePath) {
		Element e = Template.createElement(filePath);
		WeaponTemplate wt = new WeaponTemplate();

		try {
			try {
				Element speed = (Element) e.getElementsByTagName("speed").item(
						0);
				wt.speed = Float.parseFloat(speed.getAttribute("value"));
			} catch (RuntimeException ex) {
				ex.printStackTrace();
			}

			try {
				Element bulletRadius = (Element) e.getElementsByTagName(
						"bulletRadius").item(0);
				wt.bulletRadius = Float.parseFloat(bulletRadius
						.getAttribute("value"));
			} catch (RuntimeException ex) {
				ex.printStackTrace();
			}

			try {
				Element reloadTime = (Element) e.getElementsByTagName(
						"reloadTime").item(0);
				wt.reloadTime = Integer.parseInt(reloadTime
						.getAttribute("value"));
			} catch (RuntimeException ex) {
				ex.printStackTrace();
			}

			try {
				Element damage = (Element) e.getElementsByTagName("damage")
						.item(0);
				wt.damage = Integer.parseInt(damage.getAttribute("value"));
			} catch (RuntimeException ex) {
				ex.printStackTrace();
			}

			try {
				Element name = (Element) e.getElementsByTagName("name").item(0);
				wt.name = name.getAttribute("value");
			} catch (RuntimeException ex) {
				ex.printStackTrace();
			}
		} catch (RuntimeException ex) {
			ex.printStackTrace();
		}

		return wt;
	}

	@Override
	public String toString() {
		return "WeaponTemplate [bulletRadius=" + bulletRadius + ", reloadTime="
				+ reloadTime + ", damage=" + damage + ", speed=" + speed
				+ ", acceleration=" + acceleration + ", weaponName=" + name
				+ "]";
	}
}
